//
//  RecModel.swift
//

import UIKit
import CleanJSON

struct RecModel: Codable {
    var more_items = [RecChildModel]()
    var icon_items = [RecChildModel]()
    var top_items = [RecChildModel]()
}

struct RecChildModel: Codable {
    let id: String
    let contentId: String
    let title: String
    let contentType: String
    let viewType: String
    let actionType: String
    let viewParams: String
    var data: RecChildDataModel
    
    var viewP: ViewParams {
        var params = ViewParams()
        guard let data = viewParams.data(using: .utf8) else { return params }
        if let p = try? CleanJSONDecoder().decode(ViewParams.self, from: data) {
            params = p
        }
        return params
    }
    
    var layoutType: LayoutType {
        switch (contentType, viewType) {
        case ("VIDEO_CATE", "SQUARE"):
            return .hot
        case ("VIDEO", "SQUARE"), ("VIDEO", "FOCUS"):
            return .video
        case ("VIDEO_SINGLE", "FOCUS"):
            return .video_player
        case ("XT_ZL", "BIG"):
            return .big
        case ("INTER_LESSON", "BIG_LIST"):
            return .big_list
        case ("HB_BOOK", "SLIDE"):
            return .slide
        case ("HB_BOOK", "SQUARE"):
            return .book
        case ("AUDIO_CATE", "SQUARE"), ("AUDIO_CATE", "ICON"):
            return .store
        case ("AUDIO_CATE", "LIST"):
            return .store_list
        case ("URL", "ICON"):
            return .vip
        case ("AUDIO_ALBUM", "FOCUS"):
            return .audio_list
        default:
            return .video
        }
    }
}

struct RecChildDataModel: Codable {
    var id: String = ""
    var subcateid: String = ""
    var outerid: String = ""
    var subcatename: String = ""
    var icon: String = ""
    var largecover: String = ""
    var bannercover: String = ""
    var brandcover: String = ""
    var image21: String = ""
    var url: String = ""
    var image: String = ""
    var title: String = ""
    var pid: String = ""
    var atype: String = ""
    var count: String = ""
    var totalCount: String = ""
    var items: [RecChildDataItemsModel] = []
}

struct RecChildDataItemsModel: Codable {
    var vid: String = ""
    var id: String = ""
    var outerid: String = ""
    var albumId: String = ""
    var title: String = ""
    var subcatename: String = ""
    var subcatename2: String = ""
    var saleTitle: String = ""
    var url: String = ""
    var image: String = ""
    var image21: String = ""
    var bannercover: String = ""
    var image16x9: String = ""
    var image23x8: String = ""
    var subcateid: String = ""
    var studyCount: String = ""
    var count: String = ""
    var totalCount: String = ""
    var detail: String = ""
    var isSelected: Bool = false
    var program_count: String = ""
    var description: String = ""
    var pid: String
    var thumbs = StoreDetailImageModel()
    
    var storeDetail: StoreDetailModel {
        var params = StoreDetailModel()
        guard let data = detail.data(using: .utf8) else { return params }
        if let p = try? CleanJSONDecoder().decode(StoreDetailModel.self, from: data) {
            params = p
        }
        return params
    }
}

struct ViewParams: Codable {
    var itemCount: Int = 0
    var showHeader: Int = 0
    var focusUrl: String = ""
    var iconUrl: String = ""
}

struct StoreDetailModel: Codable {
    var star: Int = 0
    var title: String = ""
    var thumbs = StoreDetailImageModel()
    var id: String = ""
    var program_count: String = ""
    var description: String = ""
}

struct StoreDetailImageModel: Codable {
    var medium_thumb: String = ""
    var small_thumb: String = ""
    var large_thumb: String = ""
}

struct AudioModel: Codable {
    var album = StoreDetailModel()
    var items = [AudioItemModel]()
    var editions = [AudioURLModel]()
}

struct AudioItemModel: Codable {
    var id: String = ""
    var is_free: String = ""
    var title: String = ""
    var duration: String = ""
    var update_time: String = ""
    var album_id: String = ""
    var hd_url: String = ""
    var sd_url: String = ""
    var isSelected: Bool = false
}

struct AudioURLModel: Codable {
    let urls: [String]
}

enum LayoutType {
    case hot
    case big
    case video
    case big_list
    case slide
    case book
    case store
    case store_list
    case vip
    case video_player
    case audio_list
}
